﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DONGZHOU.Core.Common
{
    /// <summary>
    /// 导入器相关
    /// </summary>
    public class ImportDefinitionHelp
    {
        #region 单例
        private static ImportDefinitionHelp m_Instance = new ImportDefinitionHelp();

        public static ImportDefinitionHelp Instance
        {
            get => m_Instance;
        }
        #endregion

        #region 字段

        //其中AllowRecomposition=true参数就表示运行在有新的部件被装配成功后进行部件集的重组.
        [ImportMany(AllowRecomposition = true)]
        public IEnumerable<PluginBase> ModuleDefinitionImporters { get; set; }


        #endregion

        private bool m_HaveInit = false;

        private ImportDefinitionHelp()
        {


        }

        public void Init(string path)
        {
            if (m_HaveInit)
            {
                return;
            }
            if (!Directory.Exists(path))
            {
                return;
            }
            DirectoryCatalog catalog = new DirectoryCatalog(path);
            CompositionContainer container = new CompositionContainer(catalog);
            container.ComposeParts(this);
            container.ExportsChanged += Container_ExportsChanged;
         
            m_HaveInit = true;
        }



        private void Container_ExportsChanged(object sender, ExportsChangeEventArgs e)
        {
           
        }


       



    }
}
